#!/bin/sh
#
# Copyright (C) 2000-2025 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Test that reproduce bug 1227
#
TestName="bug-1227"
JobName=backuptape
. scripts/functions

require_tape_drive

scripts/copy-tape-confs
scripts/cleanup-tape

echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
start_test


# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=tape volume=TestVolume001 slot=0 pool=Default
messages
END_OF_DATA

run_bacula
stop_bacula

FILE=`awk  '/Archive Device = / { print $4 }' bin/bacula-sd.conf`
cp /dev/null $FILE

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out ${cwd}/tmp/log1.out
messages
run job=$JobName yes
@sleep 10
messages
setdebug level=400 storage=tape trace=1
setdebug level=400 director trace=1
label storage=tape volume=TestVolume002 slot=0 pool=Default
messages
@sleep 5
mount storage=tape slot=0
@sleep 2
messages
@sleep 2
mount storage=tape slot=0
@sleep 2
messages
cancel jobid=1
wait
messages
list volumes
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=tape
stop_bacula

touch ${cwd}/tmp/log2.out
check_two_logs
check_restore_diff

end_test
